package ch.usi.inf.pf2.cell;



import ch.usi.inf.pf2.node.Node;

import ch.usi.inf.pf2.cell.Value;
import ch.usi.inf.pf2.cell.NumericValue;


import junit.framework.TestCase;

public class CellTest extends TestCase {
	
	
	
	//I wanted to test the parseString ,I did it like this
	//because it did not let me to do this for that because 
	//it was private ,and with the test I show that if you 
	//give it String that contains a single number to it ,
	//it reads it correctly and represent it as a node.
	

	public void testIntNumber() {
		Parser p = new Parser(null);
		Node n = p.parseFormula("223");
		// assert that we have no syntax errors
		assertNotNull(n); 
		Value v =n.evaluate();
		// assert that we have no runtime errors
		assertNotNull(v);
		// (implicitly) assert that we get a value of the correct type (cast would throw a ClassCastException otherwise)
		NumericValue nv = (NumericValue)v;
		// assert that we get the correct value
		assertEquals(223.0, nv.get());
	}

	public void testFloatNumber() {
		Parser p = new Parser(null);
	Node n = p.parseFormula("0.9");
		assertNotNull(n);
		Value v = n.evaluate();
		assertNotNull(v);
		NumericValue nv = (NumericValue)v;
		assertEquals(0.9, nv.get());
	}

	public void testAddition() {
		Parser p = new Parser(null);
		Node n = p.parseFormula("12+3.1");
		assertNotNull(n);
		Value v = n.evaluate();
		assertNotNull(v);
		NumericValue nv = (NumericValue)v;
		assertEquals(15.1, nv.get());
	}

	public void testSubtraction() {
		Parser p = new Parser(null);
		Node n = (Node) p.parseFormula("12-3");
		assertNotNull(n);
		Value v = n.evaluate();
		assertNotNull(v);
		NumericValue nv = (NumericValue)v;
		assertEquals(9.0, nv.get());
	}

	public void testAdditionAndSubtraction() {
		Parser p = new Parser(null);
		Node n = (Node) p.parseFormula("1-2+3-4");
		assertNotNull(n);
		Value v = n.evaluate();
		assertNotNull(v);
		NumericValue nv = (NumericValue)v;
		assertEquals(-2.0, nv.get());
	}


	public void testGetStr(){
		String str = "test" ;
		Cell cell = new Cell(str,null);
		cell.getStr();
		assertEquals(str,cell.getStr());
		
	}

	public void testSetStr(){
		String str = "test" ;
		Cell cell = new Cell(str,null);
		cell.setStr(str);
		assertEquals("test",cell.getStr());
		
	}


}
